package main

import "fmt"

// 算法

/*
给定一个二叉树，判断它是否是高度平衡的二叉树。
本题中，一棵高度平衡二叉树定义为：
一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。
*/
type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isBalanced(root *TreeNode) bool {
	return true
}

func createTree(arr []int) *TreeNode {
	root := &TreeNode{}
	queue := []*TreeNode{root}
	for _, v := range arr {
		flagNone := queue[0]
		flagNone.Val = v
		queue = queue[1:]
		if v == 0 {
			continue
		}
		flagNone.Left = &TreeNode{}
		flagNone.Right = &TreeNode{}
		queue = append(queue, flagNone.Left)
		queue = append(queue, flagNone.Right)
	}
	return root
}

// 前序
func printEtreeQ(root *TreeNode) {
	if root.Val != 0 {
		fmt.Print(root.Val)
		printEtreeQ(root.Left)
		printEtreeQ(root.Right)
	}
}

// 中序
func printEtreeZ(root *TreeNode) {
	if root.Val != 0 {
		printEtreeZ(root.Left)
		fmt.Print(root.Val)
		printEtreeZ(root.Right)
	}
}

func aboutEtree() {
	arr := []int{1, 2, 0, 0, 5, 6}
	root := createTree(arr)
	printEtreeQ(root)
	fmt.Println("")
	printEtreeZ(root)
}

func countServers(grid [][]int) int {
	if len(grid) == 0 {
		return 0
	}
	h, z := len(grid), len(grid[0])
	flag := 0
	for i := 0; i < h; i++ {
		for j := 0; j < z; j++ {
			if grid[i][j] == 1 {
				flag1 := 0
				// 遍历横有没有能进行通信的
				for k, v := range grid[i] {
					if flag1 == 1 {
						break
					}
					if k != j && v == 1 {
						flag += 1
						flag1 = 1
					}
				}
				// 遍历纵有没有能通信的
				for k := 0; k < h; k++ {
					if flag1 == 1 {
						break
					}
					if k != i && grid[k][j] == 1 {
						flag += 1
						flag1 = 1
					}
				}

			}
		}
	}
	return flag
}

func donecountServers() {
	a := [][]int{
		{1, 1, 1},
		{0, 1, 0},
		{1, 0, 0},
	}
	fmt.Println(countServers(a))
}

func hammingWeight(num uint32) int {
	flag := 0
	for {
		if num == 0 {
			break
		}
		if num%2 == 1 {
			flag += 1
		}
		num /= 2
	}
	return flag
}

func testArr(arrMap *[]int) {
	*arrMap = append(*arrMap, 99)
}

func minNumber(nums1 []int, nums2 []int) int {
	minNum1, minNum2 := 10, 10
	for _, v1 := range nums1 {
		if v1 < minNum1 {
			minNum1 = v1
		}
	}
	for _, v2 := range nums2 {
		if v2 < minNum2 {
			minNum2 = v2
		}
	}
	if minNum1 == 0 {
		return minNum2
	} else if minNum1 == minNum2 {
		return minNum1
	} else {
		return minNum1*10 + minNum2
	}
}

func main() {
	arr := make([]int, 1)
	arr = append(arr, 1)
	fmt.Println(arr)
	testArr(&arr)
	fmt.Println(arr)
}
